﻿namespace MobileTrack.Web.Controllers
{
    using System;
    using System.Web.Mvc;
    using System.Web.Security;
    using MobileTrack.Core;
    using MobileTrack.Core.Data;
    using MobileTrack.Web.ActionFilters;

    [Authorize]
    [ChangePasswordRedirectActionFilter]
    public abstract class BaseController : Controller
    {
        protected BaseController(IRepositories repositories, MembershipProvider membershipProvider, RoleProvider roleProvider)
        {
            this.MembershipProvider = membershipProvider;
            this.RoleProvider = roleProvider;
            this.Repositories = repositories;
        }

        protected IRepositories Repositories { get; private set; }

        protected MembershipProvider MembershipProvider { get; private set; }

        protected RoleProvider RoleProvider { get; private set; }

        protected new MobileTrackProfile Profile
        {
            get
            {
                return base.Profile as MobileTrackProfile;
            }
        }

        protected Guid CurrentUserKey
        {
            get
            {
                return (Guid)this.MembershipProvider.GetUser(this.User.Identity.Name, true).ProviderUserKey;
            }
        }
    }
}
